import { makeObservable, observable } from 'mobx';

export const enum LoginDataIndex {
    ACCOUNT = 'account',
    PASSWORD = 'password',

    PHONE = 'phone',
    CAPTCHA = 'captcha',

    REMEMBER = 'remember',

    TOKEN = 'token',
    VALUE = 'value',

    SLIDER_CAPTCHA_STORE = 'sliderCapchaStore',
    LOGIN_TYPE = 'loginType',
    LOGIN_MODE = 'loginMode',

    // 角色相关字段
    AUTHORITY = 'authority',
}

export interface LoginData {
    [LoginDataIndex.VALUE]?: string;

    [LoginDataIndex.ACCOUNT]?: string;
    [LoginDataIndex.AUTHORITY]?: string;
    [LoginDataIndex.PASSWORD]?: string;
    [LoginDataIndex.PHONE]?: string;
    [LoginDataIndex.CAPTCHA]?: string;
    [LoginDataIndex.REMEMBER]?: boolean;
}

export const defaultData = {
    [LoginDataIndex.VALUE]: undefined,

    [LoginDataIndex.ACCOUNT]: undefined,
    [LoginDataIndex.PASSWORD]: undefined,
    [LoginDataIndex.PHONE]: undefined,
    [LoginDataIndex.CAPTCHA]: undefined,
    [LoginDataIndex.REMEMBER]: true,

    [LoginDataIndex.ACCOUNT]: 'admin',
    [LoginDataIndex.PASSWORD]: 'admin',
    [LoginDataIndex.AUTHORITY]: '',
};

export class LoginModel {
    @observable [LoginDataIndex.VALUE]?: string = undefined;

    @observable [LoginDataIndex.ACCOUNT]?: string = undefined;

    @observable [LoginDataIndex.PASSWORD]?: string = undefined;

    @observable [LoginDataIndex.PHONE]?: string = undefined;

    @observable [LoginDataIndex.CAPTCHA]?: string = undefined;

    @observable [LoginDataIndex.REMEMBER]?: boolean = true;

    @observable [LoginDataIndex.AUTHORITY]?: string = undefined;

    constructor(data: LoginData = defaultData) {
        makeObservable(this);

        this.value = data.value ?? undefined;

        this.account = data.account ?? undefined;
        this.password = data.password ?? undefined;
        this.phone = data.phone ?? undefined;
        this.captcha = data.captcha ?? undefined;
        this.remember = data.remember ?? true;
        this.authority = data.authority ?? '';
    }
}

export default LoginModel;
